//
//  PhotoPermission.m
//  YuanXinSystemPermissions
//
//  Created by 晏德智 on 2017/2/8.
//  Copyright © 2017年 晏德智. All rights reserved.
//

#import "PhotoPermission.h"
#import "PermissionType.h"
#import <Photos/Photos.h>

@implementation PhotoPermission

+ (NSString *)getStatus
{
    int status = [PHPhotoLibrary authorizationStatus];
    switch (status) {
        case PHAuthorizationStatusAuthorized:
            return RNPStatusAuthorized;
        case PHAuthorizationStatusDenied:
            return RNPStatusDenied;
        case PHAuthorizationStatusRestricted:
            return RNPStatusRestricted;
        default:
            return RNPStatusUndetermined;
    }
}

+ (void)request:(void (^)(NSString *))completionHandler
{
    void (^handler)(void) =  ^(void) {
        dispatch_async(dispatch_get_main_queue(), ^{
            completionHandler([self.class getStatus]);
        });
    };
    
    [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
        handler();
    }];
}
@end
